
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';

class CustomAppbar extends StatefulWidget implements PreferredSizeWidget {
  final String title;
  final Widget bottomWidget;
  final bool hideBack;
  final List<Widget> actions;
  final Function onTap;
  final backgroundColor;
  final leading;
  final themeColor;
  CustomAppbar({Key key, this.title, this.themeColor,this.bottomWidget, this.hideBack = false,this.actions,this.onTap,this.backgroundColor,this.leading})
      : super();
  @override
  _CustomAppbarState createState() => _CustomAppbarState();

  @override
  Size get preferredSize =>
      Size.fromHeight(bottomWidget == null ? 50.0 : 100.0);
}

class _CustomAppbarState extends State<CustomAppbar> {
  @override
  Widget build(BuildContext context) {
    return AppBar(
      elevation: 0,
      centerTitle: true,
      iconTheme: widget.themeColor==null?IconThemeData(): IconThemeData(
    color: widget.themeColor, //修改颜色
  ),
      backgroundColor: widget.backgroundColor==null? Colors.white:widget.backgroundColor,
      leading: widget.hideBack
          ? null
          : widget.leading==null? InkWell(
            onTap: widget.onTap==null? (){
              Navigator.pop(context);
            }:widget.onTap,
           child:  Image.asset(widget.themeColor==null? 'assets/images/back.png':'assets/images/back_white.png',)
          ):widget.leading,
      title: widget.title == null
          ? null
          : Text(
              widget.title,
              style: TextStyle(
                  color: widget.themeColor==null?  Color(0xff3B4859):widget.themeColor,
                  fontWeight: FontWeight.w600,
                  fontSize: ScreenUtil.getInstance().getSp(18)),
            ),
      bottom: widget.bottomWidget == null ? null : widget.bottomWidget,
      actions: widget.actions == null?null:widget.actions,
    );
  }
}
